<?php
/**
 * SBrandModel.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2019/06/26
 * Time: 22:34
 */
namespace app\common\auto_curd\php_system\model;

use think\Db;

class SBrandModel
{
    /**
     * 自增id
     */
    protected $id = '';
    public function getId()
    {
        return $this->id;
    }
    public function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * 是否启用（0否，1是）
     */
    protected $is_enable = '1';
    public function getIsEnable()
    {
        return $this->is_enable;
    }
    public function setIsEnable($is_enable)
    {
        $this->is_enable = $is_enable;
    }
    
    /**
     * 顺序
     */
    protected $sort = '0';
    public function getSort()
    {
        return $this->sort;
    }
    public function setSort($sort)
    {
        $this->sort = $sort;
    }
    
    /**
     * 添加时间
     */
    protected $create_ts = '0';
    public function getCreateTs()
    {
        return $this->create_ts;
    }
    public function setCreateTs($create_ts)
    {
        $this->create_ts = $create_ts;
    }
    
    /**
     * 更新时间
     */
    protected $update_ts = '0';
    public function getUpdateTs()
    {
        return $this->update_ts;
    }
    public function setUpdateTs($update_ts)
    {
        $this->update_ts = $update_ts;
    }
    
    /**
     * 品牌分类id
     */
    protected $bc_id = '0';
    public function getBcId()
    {
        return $this->bc_id;
    }
    public function setBcId($bc_id)
    {
        $this->bc_id = $bc_id;
    }
    
    /**
     * 名称
     */
    protected $name = '';
    public function getName()
    {
        return $this->name;
    }
    public function setName($name)
    {
        $this->name = $name;
    }
    
    /**
     * logo图标
     */
    protected $logo = '';
    public function getLogo()
    {
        return $this->logo;
    }
    public function setLogo($logo)
    {
        $this->logo = $logo;
    }
    
    /**
     * 官网地址
     */
    protected $website_url = '';
    public function getWebsiteUrl()
    {
        return $this->website_url;
    }
    public function setWebsiteUrl($website_url)
    {
        $this->website_url = $website_url;
    }
    
    /**
     * constructor.
     * @param array $data
     */
    public function __construct($data=[])
    {

        // 自增id
        if(isset($data['id']))
        {
            $this->id = $data['id'];
        }

        // 是否启用（0否，1是）
        if(isset($data['is_enable']))
        {
            $this->is_enable = $data['is_enable'];
        }

        // 顺序
        if(isset($data['sort']))
        {
            $this->sort = $data['sort'];
        }

        // 添加时间
        if(isset($data['create_ts']))
        {
            $this->create_ts = $data['create_ts'];
        }

        // 更新时间
        if(isset($data['update_ts']))
        {
            $this->update_ts = $data['update_ts'];
        }

        // 品牌分类id
        if(isset($data['bc_id']))
        {
            $this->bc_id = $data['bc_id'];
        }

        // 名称
        if(isset($data['name']))
        {
            $this->name = $data['name'];
        }

        // logo图标
        if(isset($data['logo']))
        {
            $this->logo = $data['logo'];
        }

        // 官网地址
        if(isset($data['website_url']))
        {
            $this->website_url = $data['website_url'];
        }

    }
    
    /**
     * 获取分页信息
     * @param $where
     * @param array $extend
     * @return \think\Paginator
     */
    static public function paginate($where,$extend=[])
    {
        $handler = Db::table('s_brand');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->paginate();
    }
    
    /**
     * 添加|修改
     * @param $flag
     * @param $data
     * @param array $extend
     * @return int|string
     */
    static public function save($flag,$data,$extend=[])
    {
        if(empty($flag))
        {
            // 添加
            $data['create_ts'] = time();
            return Db::table('s_brand')
                ->insertGetId($data);
        }
        else
        {
            // 编辑
            $data['update_ts'] = time();
            return Db::table('s_brand')
                ->where('id',$flag)
                ->update($data);
        }
    }
    
    /**
     * 获取详情
     * @param $where
     * @param array $extend
     * @return array|false|null|\PDOStatement|string|\think\Model
     */
    static public function get($where,$extend=[])
    {
        $handler = Db::table('s_brand');
        if(!empty($extend['field']))
        {
            $handler->field($extend['field']);
        }
        if(!empty($extend['order']))
        {
            $handler->order($extend['order']);
        }
        if(!empty($extend['group']))
        {
            $handler->group($extend['group']);
        }
        return $handler
            ->where($where)
            ->find();
    }
    
    /**
     * 删除
     * @param $flag
     * @param array $extend
     * @return int
     */
    static public function delete($flag,$extend=[])
    {
        return Db::table('s_brand')
            ->where('id',$flag)
            ->delete();
    }
}